Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

201
Views
Is there a way for me to send args[1] args[2] times?

I want my bot to be able to send someone a DM of args[1] however many times args[2] is. I think it should be pretty simple but so far I haven't found a way to do it. This is my code so far:

module.exports = {
    name: 'message',
    description: 'message',
    execute(message, args) {    
         
        let recipient = message.mentions.users.first()
        
        if (message.author.id === 'My ID') {
            recipient.send(args[1])
        }       
            if ((!args[1])) return message.channel.send('Please include the message you want to send.')            
            if (isNaN(args[2])) return message.channel.send('Please include how many times you want the message to send.')
    }          
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use a simple for loop:

module.exports = {
  name: 'message',
  description: 'message',
  execute(message, args) {
    let recipient = message.mentions.users.first();

    if (!args[1])
      return message.channel.send(
        'Please include the message you want to send.',
      );
    if (isNaN(args[2]))
      return message.channel.send(
        'Please include how many times you want to send the message.',
      );

    if (message.author.id === 'My ID') {
      for (let i = 0; i < args[2]; i++) {
        recipient.send(args[1]);
      }
    }
  },
};
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!